from odoo import api, models, fields
from odoo.exceptions import ValidationError


class MrpWorkorder(models.Model):
    _inherit = 'mrp.workorder'

    def chargeback(self):
        production = self.production_id
        if production.s_mes_lock:
            raise ValidationError('当前工单已同步到MES系统，无法在odoo操作。')
        res = super().chargeback()
        return res
